package examples
{
	import com.wskeee.ec.components.Alert;
	import com.wskeee.ec.components.Button;
	import com.wskeee.ec.components.Label;
	import com.wskeee.ec.components.TextInput;
	import com.wskeee.ec.containers.Container;
	import com.wskeee.ec.containers.HBox;
	import com.wskeee.ec.containers.VBox;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;

	public class AlertExmaple
	{
		public static function createAlert():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "Alert";
			mainBox.verticalGap = 10;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.addChild(head);
			
			//---------------------
			//enter & cancel label
			//---------------------
			var labelBox:HBox = new HBox();
			var label:Label = new Label();
			var enterLabel:TextInput,cancelLabel:TextInput;
			label.text = "enterLabel: ";
			labelBox.addChild(label);
			enterLabel = new TextInput("确定");
			enterLabel.width = 50;
			labelBox.addChild(enterLabel);
			mainBox.addChild(labelBox);
			
			labelBox = new HBox();
			label = new Label();
			label.text = "cancelLabel: ";
			labelBox.addChild(label);
			cancelLabel = new TextInput("取消");
			cancelLabel.width = 50;
			labelBox.addChild(cancelLabel);
			mainBox.addChild(labelBox);
			//---------------------
			//flag
			//---------------------
			var flagBox:HBox = new HBox();
			var labels:Array = ["enter","cancel","enter | cancel"];
			var labelValues:Object = {enter:1,cancel:2,'enter | cancel':3};
			var lastControlButton:Button;
			var button:Button;
			for(var i:int=0;i<3;i++)
			{
				button = new Button();
				button.toggle =true;
				button.label = labels[i];
				button.selected = false;
				button.addEventListener(MouseEvent.CLICK,changeVBoxHAlign);
				flagBox.addChild(button);
			}
			mainBox.addChild(flagBox);
			lastControlButton = flagBox.getChildAt(0) as Button;
			lastControlButton.selected = true;
			function changeVBoxHAlign(evt:Event):void
			{
				if(lastControlButton!=evt.currentTarget && lastControlButton)
					lastControlButton.selected = false;
				lastControlButton = evt.currentTarget as Button;
			}
			
			//---------------------
			//modal
			//---------------------
			var modalButton:Button = new Button();
			modalButton.label = "modal";
			modalButton.toolTip = "是否启用冻结舞台功能"
			modalButton.toggle = true;
			modalButton.selected = true;
			mainBox.addChild(modalButton);
			//---------------------
			//title
			//---------------------
			var titleBox:HBox = new HBox();
			label = new Label();
			label.text = "标题";
			var titleField:TextInput= new TextInput("标题");
			titleBox.addChild(label);
			titleBox.addChild(titleField);
			mainBox.addChild(titleBox);
			
			//---------------------
			//text
			//---------------------
			var textBox:HBox = new HBox();
			label = new Label();
			label.text = "提示: ";
			var textField:TextInput = new TextInput("提示信息");
			textField.height = 100;
			textBox.addChild(label);
			textBox.addChild(textField);
			mainBox.addChild(textBox);
			
			var pop:Button = new Button();
			pop.label = "弹出";
			pop.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void
			{
				Alert.enterLabel = enterLabel.text;
				Alert.cancelLabel = cancelLabel.text;
				
				Alert.show(textField.text,
					titleField.text,
					labelValues[lastControlButton.label],
					null,
					modalButton.selected,
					function(obj:Object):void
					{
						//obj.detail == Alert.ENTER,Alert.CANCEL
						trace(obj.detail)
					});
					
			});
			mainBox.addChild(pop);
			return mainBox;
		}
	}
}